package com.ruoyi.gams.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gams.domain.GamsDepartment;
import com.ruoyi.gams.service.IGamsDepartmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部门Controller
 *
 * @author ruoyi
 * @date 2021-09-03
 */
@RestController
@RequestMapping("/gams/department")
public class GamsDepartmentController extends BaseController
{
    @Autowired
    private IGamsDepartmentService gamsDepartmentService;

    /**
     * 查询部门列表
     */
    @PreAuthorize("@ss.hasPermi('gams:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(GamsDepartment gamsDepartment)
    {
        startPage();
        List<GamsDepartment> list = gamsDepartmentService.selectGamsDepartmentList(gamsDepartment);
        return getDataTable(list);
    }

    /**
     * 导出部门列表
     */
    @PreAuthorize("@ss.hasPermi('gams:department:export')")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GamsDepartment gamsDepartment)
    {
        List<GamsDepartment> list = gamsDepartmentService.selectGamsDepartmentList(gamsDepartment);
        ExcelUtil<GamsDepartment> util = new ExcelUtil<GamsDepartment>(GamsDepartment.class);
        return util.exportExcel(list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    @PreAuthorize("@ss.hasPermi('gams:department:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(gamsDepartmentService.selectGamsDepartmentById(id));
    }

    /**
     * 新增部门
     */
    @PreAuthorize("@ss.hasPermi('gams:department:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GamsDepartment gamsDepartment)
    {
        return toAjax(gamsDepartmentService.insertGamsDepartment(gamsDepartment));
    }

    /**
     * 修改部门
     */
    @PreAuthorize("@ss.hasPermi('gams:department:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GamsDepartment gamsDepartment)
    {
        return toAjax(gamsDepartmentService.updateGamsDepartment(gamsDepartment));
    }

    /**
     * 删除部门
     */
    @PreAuthorize("@ss.hasPermi('gams:department:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(gamsDepartmentService.deleteGamsDepartmentByIds(ids));
    }
}
